#include<iostream>
#include<cstring> 
#include<algorithm> 
using namespace std;
const int N = 2e4 + 10;
int n, m;
int b[N];
int arr[N];
void fun(int arr[], int l, int r)
{
	if (l >= r)return;
	int i = l - 1;
	int j = r + 1;
	int mid = (l + r) >> 1;
	int x = arr[mid];
	while (i < j) {
		do {
			i++;
		} while (arr[i] < x);
		do {
			j--;
		} while (arr[j] > x);
		if (i < j) {
			swap(arr[i], arr[j]);
		}
	}
	fun(arr, l, j);
	fun(arr, j + 1, r);
}
int main()
{
	while (cin >> n >> m) {
		memset(arr, 0, sizeof(arr));
		memset(b, 0, sizeof(b));
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		for (int i = n; i < n + m; i++) {
			cin >> arr[i];
		}
		int cnt = 0;
		fun(arr, 0, n + m - 1);
		for (int i = 0; i < n + m; i++) {
			if (!i || arr[i] != arr[i - 1]) {
				b[cnt++] = arr[i];
			}
		}
		cout << b[0];
		for (int i = 1; i < cnt; i++) {
			cout << " " << b[i];
		}
		cout << endl;
	}
	return 0;
}